
// <copyright file="EnumeratorBasedDataReaderStrategy.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The enumerator based data reader strategy.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Data
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// The enumerator based data reader strategy.
    /// </summary>
    /// <typeparam name="T">
    /// </typeparam>
    public class EnumeratorBasedDataReaderStrategy<T> : GenericDataReaderStrategy<T>
        where T : class
    {
        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="EnumeratorBasedDataReaderStrategy{T}"/> class.
        /// </summary>
        /// <param name="enumerator">
        /// The enumerator.
        /// </param>
        /// <param name="columns">
        /// The columns.
        /// </param>
        /// <param name="populateItemArrayDelegate">
        /// The populate item array delegate.
        /// </param>
        public EnumeratorBasedDataReaderStrategy(IEnumerator<T> enumerator, IList<KeyValuePair<string, Type>> columns, PopulateItemArrayDelegate<T> populateItemArrayDelegate)
            : base(columns, delegate
                {
                    if (enumerator.MoveNext())
                    {
                        return enumerator.Current;
                    }

                    return default(T);
                }, populateItemArrayDelegate, null)
        {
        }

        #endregion Constructors and Finalizers
    }
}